#include <iostream>
#include <algorithm>
#include <xscript/xfilereader.h>
#include <xscript/xlexer.h>

int main() {
    std::string file = "./../script/set.x";

    XFileReader reader;
    reader.open(file);

    XLexParser parser;

    int32_t line = 1;
    while (!reader.eof()) {
        auto text = reader.readLine();
        if (!parser.parse(text, line++)) {
            if (XScriptExecutor::getInstance()->hasError())
                break;
        }
    }

    if (XScriptExecutor::getInstance()->hasError())
        std::wcout << "find error:" << XScriptExecutor::getInstance()->getErrorType() << std::endl;
    else {
        auto tokenLine = parser.getTokens();
        for (const auto& tokens : tokenLine) {
            std::wcout << "line:" << tokens.line << " block:" << tokens.tokens.at(0)->getBlock() << std::endl;
            for (auto& token : tokens.tokens)
                std::wcout << token->getString() << " ";
            std::wcout << std::endl;
        }
    }
    return 1;
}


